package com.mxc.scratch.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lww.springcloudapi.entity.TabEmployee;
import com.lww.springcloudapi.entity.TabGgcardInfo;
import com.lww.springcloudapi.pojo.TabHallUser;
import com.lww.springcloudapi.result.Result;
import com.lww.springcloudapi.result.ResultCodeEnum;
import com.mxc.scratch.service.TabGgcardInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.List;

/**
 * <p>
 * 刮刮卡信息表 前端控制器
 * </p>
 *
 * @author SHEN
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/ggcardinfo")
//@CrossOrigin
public class TabGgcardInfoController {

    @Autowired
    TabGgcardInfoService tabGgcardInfoService;


    /**
     * 刮奖卡管理模块查询业务
     *
     * @param prizelevel 礼品等级  ，  state 刮刮卡状态 00未刮  10 已刮
     * @return
     */
    @ApiOperation(value = "刮奖卡管理模块查询业务")
    @PostMapping("/get")
//    @HystrixCommand(fallbackMethod = "hystrixGet")
    public Result getByAreaid(@RequestParam(required = false) String prizelevel,
                              @RequestParam(required = false) String state,
                              @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                              @RequestParam(required = false, defaultValue = "5") Integer pageSize,TabEmployee tabEmployee) {

        try {
            tabEmployee.setAcptsiteid("46");
            Page page = tabGgcardInfoService.queryByAreaId(tabEmployee.getAcptsiteid(),prizelevel, state, pageNo, pageSize);
            return Result.ok(page);
        } catch (Exception e) {
            return Result.fail(ResultCodeEnum.FAIL);
        }

    }


    /**
     *
     * @param prizelevel 礼品等级，stocknum 入库数量
     * @return
     */
    @ApiOperation("刮奖卡管理模块录入业务")
    @PostMapping("/addInfo")
//    @HystrixCommand(fallbackMethod = "hystrixGet")
    public Result inserInfo(Integer prizelevel, Integer stocknum, TabEmployee tabEmployee) {
        try {
            tabEmployee.setEname("小乐").setAcptsiteid("46");
            boolean b = tabGgcardInfoService.inserInfo(prizelevel, stocknum, tabEmployee);
            return Result.ok(b);
        } catch (Exception e) {
            return Result.fail(ResultCodeEnum.FAIL);
        }
    }

    /**
     * 刮奖卡管理模块修改业务
     *
     * @param
     * @return
     */
    @ApiOperation("刮奖卡管理模块修改业务")
    @PostMapping("/updateInfo")
//    @HystrixCommand(fallbackMethod = "hystrixGet")
    public Result updateInfo(TabGgcardInfo tabGgcardInfo, TabEmployee tabEmployee) {
        try {
            tabEmployee.setEname("小乐").setAcptsiteid("46");
            boolean b = tabGgcardInfoService.updateInfo(tabGgcardInfo, tabEmployee);
            return Result.ok(b);
        } catch (Exception e) {
            return Result.fail(ResultCodeEnum.FAIL);
        }
    }

    /**
     * 刮奖卡管理模块删除业务
     *
     * @param cardno 卡序列号
     * @return
     */
    @ApiOperation("刮奖卡管理模块删除业务")
    @PostMapping("/deleteInfo/{cardno}")
//    @HystrixCommand(fallbackMethod = "hystrixGet")
    public Result deleteInfo(@PathVariable("cardno") String cardno) {
        try {
            boolean b = tabGgcardInfoService.deleteInfo(cardno);
            return Result.ok(b);
        } catch (Exception e) {
            return Result.fail(ResultCodeEnum.FAIL);
        }
    }

    /**
     * 用户输入手机号查询该（操作员）营业厅未领取的刮刮卡
     * ,pnumber 用户输入的手机号
     * tabHallUser.getPnumber()操作员手机号
     *
     * @param
     * @return
     */
    @ApiOperation("用户输入手机号查询该（操作员）营业厅未领取的刮刮卡")
    @GetMapping("/listInfo")
    public Result listInfo(String yhpnumber, TabHallUser tabHallUser) {
        try {
            String s = tabGgcardInfoService.listScrapingCard(yhpnumber, tabHallUser.getPnumber());
            return Result.ok(s);
        } catch (Exception e) {
            return Result.fail(ResultCodeEnum.FAIL);
        }
    }


    //服务熔断
    public String hystrixGet(TabGgcardInfo tabGgcardInfo) {
        return "出现异常";
    }

}

